using UnityEngine;
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks;
using Gameplay;

public class UseSkill : Action
{
	public int SkillId;
	public float EscapeDistance;
	public SharedTransform Target;

    private Character _character;
	public override void OnStart()
	{
		_character = GetComponent<Character>();
	}

	public override TaskStatus OnUpdate()
	{
		if(Vector3.Distance(new Vector3(Target.Value.position.x, 0, Target.Value.position.z), new Vector3(transform.position.x, 0, transform.position.z))>=EscapeDistance)
		{
			return TaskStatus.Failure;
		}
		_character.SkillManager.UseSkill(SkillId);
		return TaskStatus.Success;
	}
}